import {create} from 'dva-core';

let app, store, dispatch, registered;

function createApp(option) {
    option.onAction = []
    app = create(option);
    if (!registered) {
      option.models.forEach(e => app.model(e));
    }
    registered = true;
    app.start();
    store = app._store;
    app.getStore = () => store;
    app.use({
        onError(error) {
            console.error('[DVA ERROR]', error)
        }
    })

    dispatch = store.dispatch;
    app.dispatch = dispatch;

    return app;
}
export default {
    createApp,
    getDispatch() {
        return app.dispatch;
    }
}
